const host_url = 'https://apis.netstart.cn/yunyuedu';

//首页导航
export const getSlideshow= ()=> {
	return new Promise((resolve,reject)=>{
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/store/navi.json?gender=2`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}
//排行榜
export const getRankingshow= ()=> {
	return new Promise((resolve,reject)=>{
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/store/merged/rankNavi.json?uuid=b229b022871941fea35edc7aceeed1ab&rankType=27&all=0`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}

//排行榜内容
export const getRankingContent= (myurl)=> {
	return new Promise((resolve,reject)=>{
		console.log(`${host_url}${myurl}`);
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}${myurl}`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}

//各导航内容
export const getSlideContent= (myurl)=> {
	return new Promise((resolve,reject)=>{
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}${myurl}`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}


//获取分类页导航栏
export const getClassifyNav= (myurl)=> {
	return new Promise((resolve,reject)=>{
		uni.request({
			url: `${host_url}/store/node.json?gender=1`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}

//获取分类页导航栏二级分类
export const getSecondClassifyNav= (myurl)=> {
	return new Promise((resolve,reject)=>{
		uni.request({
			url: `${host_url}${myurl}`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}
//获取分类页导航栏二级分类结果筛选条件
export const getSecondClassifyResult= (myurl)=> {
	return new Promise((resolve,reject)=>{
		uni.request({
			url: `${host_url}${myurl}`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}
//获取小说筛选结果
export const getResult= (myurl)=> {
	return new Promise((resolve,reject)=>{
		uni.request({
			url: `${host_url}${myurl}`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}

//获取小说详情
// /book/getsub.json?id=13c58cc086f74e36978b4a7881b82517_4&title=女掌事
export const getFictionDetail= (id,title)=> {
	return new Promise((resolve,reject)=>{
		uni.request({
			url: `${host_url}/book/getsub.json?id=${id}&title=${title}`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}
//获取章节列表
export const getSectionList= (id)=> {
	return new Promise((resolve,reject)=>{
		uni.request({
			url: `${host_url}/reader/book/info.json?source_uuid=${id}`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}

//获取章节内容
export const getSectionContent= (bookid,secid)=> {
	return new Promise((resolve,reject)=>{
		// console.log(bookid,secid,1111111111);
		uni.request({
			url: `${host_url}/reader/book/content.json?source_uuid=${bookid}&content_uuid=${secid}`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}

//小说搜索建议
export const getSearchSuggest= (val)=> {
	return new Promise((resolve,reject)=>{
		console.log(val,1111111111);
		uni.request({
			url: `${host_url}/search/searchHint?search=${val}`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}
//小说搜索结果
export const getSearchResult= (val)=> {
	return new Promise((resolve,reject)=>{
		uni.request({
			url: `${host_url}/search/book.json?keyword=${val}`,
			success(content) {
				let {errMsg,data}=content
				if(errMsg == "request:ok") {
					resolve(data)
				}
				else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			},
			fail(err) {
				reject(err);
			}
		})
	})
}